package bigapps.myneighbor.controller.ws.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;

import bigapps.myneighbor.controller.ws.ParkingFacilityWSController;
import bigapps.myneighbor.domain.Location;
import bigapps.myneighbor.domain.ParkingFacility;
import bigapps.myneighbor.domain.ParkingFacilityList;
import bigapps.myneighbor.service.ParkingFacilityService;

@Endpoint
public class ParkingFacilityWSControllerImpl implements ParkingFacilityWSController {
	@Autowired
	public ParkingFacilityService parkingFacilityService;

	@PayloadRoot(localPart="Location", namespace="http://test.com")
	public ParkingFacilityList getParkingFacilityListXMLWS(Location location){
		Float latitude = location.getLatitude();
		Float longitude = location.getLongitude();
		System.out.println("latitude: " + latitude + ", longitude: " + longitude);
		System.out.println("xml");
		return getParkingFacilityList(latitude, longitude);
	}

	@PayloadRoot(localPart="getClosesParkingFacilityXMLWSRequest", namespace="http://test.com")
	public ParkingFacility getClosesParkingFacilityXMLWS(){
		Float latitude = new Float(5.0);
		Float longitude = new Float(5.0);
		System.out.println("latitude: " + latitude + ", longitude: " + longitude);
		System.out.println("xml");
		return getParkingFacilityList(latitude, longitude).parkingFacilityList.get(0);
	}

	private ParkingFacilityList getParkingFacilityList(double latitude, double longitude)
	{
		try{
			System.out.println("getParkingFacilityList");
			return parkingFacilityService.getParkingFacilityList(latitude, longitude);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}
}
